<?php
/**
 * Allow create exchange with association account
 *
 * @package    letsManager
 * @subpackage form
 * @author     Jerome Fouilloy
 * @version    SVN: $Rev$
 */
class LetsMassPaymentForm extends BaseForm
{
  /** Credit member and debit association */
  const PAYMENT_CREDIT = 'credit';
  /** Debit member and credit association */
  const PAYMENT_DEBIT = 'debit';

  public function setup()
  {
    parent::setup();
    $user = sfContext::getInstance()->getUser();

    $qCategories = LetsMainCategoryTable::getQueryForUser($user,true);

    $paymentType = array(self::PAYMENT_DEBIT => 'Membres => Association',self::PAYMENT_CREDIT => 'Association => Membres');
    $this->setWidgets(array(
      'name' => new sfWidgetFormInputText(array(),array('class' => 'formInputLarge')),
      'category_id' => new sfWidgetFormDoctrineChoice(array(
      'model' => 'LetsMainCategory',
      'query' => $qCategories,
    )),
      'type' => new sfWidgetFormChoice(array(
      'choices' => $paymentType
    )),
      'amount' => new sfWidgetFormInputText(array(),array('class' => 'formInputShort')),
    ));
    
    $this->setValidators(array(
      'category_id'=> new sfValidatorDoctrineChoice(array(
      'model' => 'LetsMainCategory',
      'query' => $qCategories
    )),
      'name' 		=> new sfValidatorString(array('max_length' => 255)),
      'type'		=> new sfValidatorChoice(array('choices' => array(self::PAYMENT_CREDIT,self::PAYMENT_DEBIT))),
      'amount'	=> new sfValidatorInteger(array('min' => 1)),
    ));

    $this->widgetSchema->setLabels(array(
      'category_id' => 'Catégorie',
      'name' => 'Description',
      'amount' => 'Montant par adhérent',
      'type' => 'Type de paiement',
    ));
    $this->widgetSchema->setNameFormat('lets_mass_payment[%s]');
  }
}